// 寻找重复数

package Leetcode;

class Solution287 {
    public int findDuplicate(int[] nums) {
        int slow = 0, fast = 0;
        // 判圈
        do {
            slow = nums[slow];
            fast = nums[nums[fast]];
        } while (fast != slow);
        // 找到圈的起点
        slow = 0;
        while (fast != slow) {
            slow = nums[slow];
            fast = nums[fast];
        }
        return slow;
    }
}
